#include <iostream>
#include <cstdio>
#include <algorithm> 

using namespace std; 

#define N 1001

int s[N][N]; 
int a[N][N]; 

int main()
{
	int r, n, i, j; 
	
	//freopen("p1286.in", "r", stdin); 
	
	cin>>n;
	for (i=1; i<=n; i++) {
		for (j=1; j<=i; j++) {
			cin>>a[i][j]; 
		}
	}
	
	for (i=1; i<=n; i++) {
		for (j=1; j<=i; j++) {
			s[i][j] = a[i][j] + max(s[i-1][j-1], s[i-1][j]); 
		}
	}
	for (r=0, i=1; i<=n; i++) {
		r = max(r, s[n][i]); 
	}
	cout<<r<<endl; 
	return 0; 
}

